<?php

// /usr/share/php in path
require_once('Zend/Service/LiveDocx/MailMerge.php');

class LivedocxBroker
{
	public $phpLiveDocx = null;
	/**
	 * Loads LiveDocx lib and also logs into LiveDocx account.
	 */
	public function __construct()
	{
		$this->phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();		
		$this->phpLiveDocx->setUsername('resumebuilder');
		$this->phpLiveDocx->setPassword('tennis01');
	}
	/**
	 *  not really needed.. login takes place in constructor..
	 */
	public function login()
	{
		$this->phpLiveDocx->setUsername('resumebuilder');
		$this->phpLiveDocx->setPassword('tennis01');
	}
	
	/**
	 * logs out
	 */
	public function logout()
	{
		$this->phpLiveDocx->logOut();
	}

	/**
	 * 
	 * @param String $template - set as 'default' to use default template
	 */
	public function setTemplate($template)
	{
		if( $template == 'default')
		{
			$this->phpLiveDocx->setRemoteTemplate('resume-template.docx');
		}
		else
		{
			$this->phpLiveDocx->setRemoteTemplate($template);				
		}
	}
	
	/**
	 * 
	 * @param String $field
	 * @param String $value
	 */
	public function setField($field, $value)
	{
		$this->phpLiveDocx->setFieldValue($field, $value);
	}
	
	/**
	 * 
	 * @param String $localFile
	 * @param String $format = use either DOC, DOCX, HTML, PDF, RTF, TXD, TXT
	 */
	public function downloadResume($localFile,$format)
	{
		$this->phpLiveDocx->createDocument();
		$document = $this->phpLiveDocx->retrieveDocument($format);
		file_put_contents($localFile, $document);			
	}
}

?>
